@page
@model B.WMS.Web.Pages.Inventory.EditModel
@{
    ViewData["Title"] = "盘点编辑";
}

<div class="container-fluid">
    <form id="inventoryForm">
        <!-- 基础信息区域 -->
        <div class="card mb-3">
            <div class="card-header">
                <h5 class="mb-0">基础信息</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>盘点单号</label>
                            <input type="text" class="form-control" id="reviewNo" value="自动获取系统编号" readonly>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>盘点类型 <span class="text-danger">*</span></label>
                            <select class="form-control" id="reviewType" required>
                                <option value="">请选择</option>
                                <option value="存货盘点">存货盘点</option>
                                <option value="循环盘点">循环盘点</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>盘点开始时间 <span class="text-danger">*</span></label>
                            <input type="datetime-local" class="form-control" id="startTime" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>盘点结束时间 <span class="text-danger">*</span></label>
                            <input type="datetime-local" class="form-control" id="endTime" required>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>仓库名称 <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <select class="form-control" id="warehouseName" required>
                                    <option value="">请选择</option>
                                    <option value="货品仓库一">货品仓库一</option>
                                    <option value="货品仓库二">货品仓库二</option>
                                </select>
                                <div class="input-group-append">
                                    <button type="button" class="btn btn-outline-secondary" onclick="openWarehouseSettings()">设置</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label>经办人 <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <select class="form-control" id="userId" required>
                                    <option value="">请选择</option>
                                    <option value="1">李依依</option>
                                    <option value="2">潘悦恺</option>
                                </select>
                                <div class="input-group-append">
                                    <button type="button" class="btn btn-outline-secondary" onclick="selectUser()">...</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label>备注</label>
                    <textarea class="form-control" id="remark" rows="3" placeholder="请输入"></textarea>
                </div>
            </div>
        </div>

        <!-- 盘点明细区域 -->
        <div class="card mb-3">
            <div class="card-header">
                <h5 class="mb-0">盘点明细</h5>
            </div>
            <div class="card-body">
                <!-- 操作按钮 -->
                <div class="row mb-3">
                    <div class="col-md-6">
                        <button type="button" class="btn btn-success" onclick="addItem()">
                            <i class="fas fa-plus"></i> 添加
                        </button>
                        <button type="button" class="btn btn-secondary" onclick="removeSelected()">
                            <i class="fas fa-minus"></i> 移除
                        </button>
                        <button type="button" class="btn btn-info" onclick="importItems()">
                            <i class="fas fa-upload"></i> 导入
                        </button>
                    </div>
                    <div class="col-md-6 text-right">
                        <div class="alert alert-warning d-inline-block mb-0">
                            <i class="fas fa-exclamation-triangle"></i> 请选择仓库!
                        </div>
                        <div class="alert alert-warning d-inline-block mb-0 ml-2">
                            <i class="fas fa-exclamation-triangle"></i> 请选择货品!
                        </div>
                    </div>
                </div>

                <!-- 明细表格 -->
                <div class="table-responsive">
                    <table class="table table-striped table-hover" id="detailTable">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="selectAllDetails" onchange="toggleSelectAllDetails()">
                                </th>
                                <th>序号</th>
                                <th>货品名称</th>
                                <th>货品编号</th>
                                <th>规格型号</th>
                                <th>单位</th>
                                <th>货品类型</th>
                                <th>账面库存</th>
                                <th>账面金额</th>
                                <th>盘点库位</th>
                                <th>盘点数量 <span class="text-danger">*</span></th>
                                <th>盈亏数量</th>
                                <th>盘点状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="detailTableBody">
                            <!-- 数据将通过JavaScript动态加载 -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- 合计区域 -->
        <div class="card mb-3">
            <div class="card-header">
                <h5 class="mb-0">合计</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>账面库存</label>
                            <input type="text" class="form-control" id="totalBookedInventory" value="25" readonly>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>账面金额</label>
                            <input type="text" class="form-control" id="totalBookedAmount" value="25.00" readonly>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>盘点数量</label>
                            <input type="text" class="form-control" id="totalCountedQuantity" value="25" readonly>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>盘盈数量</label>
                            <input type="text" class="form-control text-success" id="totalSurplusQuantity" value="3" readonly>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>盘亏数量</label>
                            <input type="text" class="form-control text-danger" id="totalLossQuantity" value="1" readonly>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>盘盈金额</label>
                            <input type="text" class="form-control text-success" id="totalSurplusAmount" value="250.00" readonly>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>盘亏金额</label>
                            <input type="text" class="form-control text-danger" id="totalLossAmount" value="250.00" readonly>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 操作按钮 -->
        <div class="card">
            <div class="card-body">
                <button type="button" class="btn btn-primary" onclick="saveInventory()">
                    <i class="fas fa-save"></i> 保存
                </button>
                <button type="button" class="btn btn-secondary" onclick="goBack()">
                    <i class="fas fa-arrow-left"></i> 返回
                </button>
            </div>
        </div>
    </form>
</div>

<!-- 添加货品模态框 -->
<div class="modal fade" id="addItemModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">添加货品</h5>
                <button type="button" class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>搜索货品</label>
                    <input type="text" class="form-control" id="searchGoods" placeholder="请输入货品名称或编号">
                </div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover" id="goodsTable">
                        <thead>
                            <tr>
                                <th>选择</th>
                                <th>货品名称</th>
                                <th>货品编号</th>
                                <th>规格型号</th>
                                <th>单位</th>
                                <th>货品类型</th>
                                <th>账面库存</th>
                                <th>账面金额</th>
                            </tr>
                        </thead>
                        <tbody id="goodsTableBody">
                            <!-- 货品列表将通过JavaScript动态加载 -->
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmAddItems()">确定添加</button>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script src="~/Pages/Inventory/Edit.js"></script>
} 